package cn.iocoder.yudao.module.blog.convert.follow;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.follow.vo.AppBlogFollowRespVO;
import cn.iocoder.yudao.module.blog.controller.app.space.commentvo.AppBlogSpaceCommentRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.spacecomment.BlogSpaceCommentDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.follow.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.follow.BlogFollowDO;

/**
 * 关注 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogFollowConvert {

    BlogFollowConvert INSTANCE = Mappers.getMapper(BlogFollowConvert.class);

    BlogFollowDO convert(BlogFollowCreateReqVO bean);

    BlogFollowDO convert(BlogFollowUpdateReqVO bean);

    BlogFollowRespVO convert(BlogFollowDO bean);

    List<BlogFollowRespVO> convertList(List<BlogFollowDO> list);

    PageResult<BlogFollowRespVO> convertPage(PageResult<BlogFollowDO> page);

    List<BlogFollowExcelVO> convertList02(List<BlogFollowDO> list);

    default AppBlogFollowRespVO convertApp(BlogFollowDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }

        AppBlogFollowRespVO appBlogFollowRespVO = new AppBlogFollowRespVO();

        appBlogFollowRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogFollowRespVO.setId(bean.getId());
        appBlogFollowRespVO.setFollowMemberId(bean.getFollowMemberId());
        appBlogFollowRespVO.setCreateTime(bean.getCreateTime());
        appBlogFollowRespVO.setMemberId(bean.getMemberId());

        return appBlogFollowRespVO;
    }

    default List<AppBlogFollowRespVO> convertAppList(List<BlogFollowDO> blogFollowDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogFollowRespVO> list = new ArrayList<>();
        blogFollowDOList.forEach(blogFollowDO -> {
            list.add(convertApp(blogFollowDO, memberMap.get(blogFollowDO.getFollowMemberId())));
        });

        return list;
    }

    default PageResult<AppBlogFollowRespVO> convertAppPage(PageResult<BlogFollowDO> page, Map<Long, MemberUserRespDTO> memberMap){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogFollowRespVO> pageResult = new PageResult<AppBlogFollowRespVO>();
        List<AppBlogFollowRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
